<?php
/**
 * -----------------------------------------------------
 *
 * models Value_models
 *
 * @package     models
 * @subpackage  
 * @category    Value_model  -  产品属性值模型类
 * @author      ChenFu
 * @since       2015-6-17 version 1.0
 * -----------------------------------------------------    
 */
class Value_model extends CI_Model
{    
	public static $error;
	const TABLE = 'xc_pro_attribute_value'; // 表名
	private static $str_options; 	// 
	public function __construct()
	{
		parent::__construct();
        $this->load->database();
	}

	/**
	 * 增加数据
	 */
	public function insert($data)
	{
		if($this->db->insert(self::TABLE,$data)){
			return true;
		}else{
			return false;
		}
	}

 	/**
	 * 增加数据- 地区
	 */
	public function insert_region($data)
	{
		if($this->db->insert('xc_pro_region',$data)){
			return true;
		}else{
			return false;
		}
	}

 	/**
	 * 增加数据- 
	 */
	public function insert_value($data)
	{
		if($this->db->insert(self::TABLE,$data)){
			return true;
		}else{
			return false;
		}
	}


	/**
	 * [get_region_by_pid_and_aid 查询地区列表]
	 * @param  [type] $pid [description]
	 * @param  [type] $aid [description]
	 * @return [type]      [description]
	 */
	public function get_region_by_pid_and_aid($pid,$aid){
		$this->db->where('pro_id',$pid);
		$this->db->where('attr_id',$aid);
		$this->db->order_by('reg_sort','asc');
		$query = $this->db->get('xc_pro_region');
		if($query->num_rows()){
			return $query->result_array();
		}
	}


	public function get_a_value_by_id($id){
		$this->db->where('attr_id',$id);
		$query = $this->db->get(self::TABLE);
		if($query->num_rows()){
			return $query->row_array();
		}
	}

	public function get_value_by_id($id){
		$this->db->where('attr_id',$id);
		$this->db->order_by('val_sort','asc');
		$query = $this->db->get(self::TABLE);
		if($query->num_rows()){
			return $query->result_array();
		}
	}


	/**
	 * [region_delete 删除数据]
	 * @return [type] [description]
	 */
	public function region_delete($id){
		$this->db->where('reg_id',$id);
		if($this->db->delete('xc_pro_region')){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * [region_delete 删除数据]
	 * @return [type] [description]
	 */
	public function value_delete($id){
		$this->db->where('val_id',$id);
		if($this->db->delete(self::TABLE)){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * [update_region 更新数据]
	 * @param  [type] $data [description]
	 * @param  [type] $id   [description]
	 * @return [type]       [description]
	 */
	public function update_region($data,$id){
		if($this->db->update('xc_pro_region',$data,'reg_id = '.$id)){
			return true;
		}else{
			return false;
		}
	}

	/**
	 * [update_value 更新数据]
	 * @param  [type] $data [description]
	 * @param  [type] $id   [description]
	 * @return [type]       [description]
	 */
	public function update_value($data,$id){
		if($this->db->update(self::TABLE,$data,'val_id = '.$id)){
			return true;
		}else{
			return false;
		}
	}
}